package com.ruoyi.yuyuan.Controller;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import com.ruoyi.yuyuan.DTO.Result;
import com.ruoyi.yuyuan.Mapper.UserMapper;
import com.ruoyi.yuyuan.Service.IUploadService;
import com.ruoyi.yuyuan.Utils.COSUtils;
import com.ruoyi.yuyuan.Utils.SystemConstants;
import com.ruoyi.yuyuan.Utils.UserHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;


@Slf4j
@RestController
@RequestMapping("/upload")
public class UploadController {
    @Autowired
    private IUploadService uploadService;

    /**
     * 上传图片
     *
     * @param images 图片数组
     * @return 图片路径
     */
    @PostMapping("/images")
    public String uploadImages(@RequestParam("file") MultipartFile[] images) {
        return uploadService.uploadImages(images);
    }

    @PostMapping("/iconImage")
    public String uploadIconImage(@RequestParam("file") MultipartFile image) {
        return uploadService.uploadIconImage(image);
    }

    /**
     * 根据路径删除存储桶中的图片
     *
     * @param filePath 图片链接
     * @return 空
     */
    @GetMapping("/blog/delete")
    public Result deleteBlogImage(@RequestParam("name") String filePath) {
        return uploadService.deleteBlogImage(filePath);
    }

    /**
     * 获取存储桶临时凭证
     *
     * @return List
     */
    @GetMapping("/cos/tmpInfo")
    public Result getCosTmpInfo() {
        return uploadService.getCosTmpInfo();
    }

}
